package exer;

/**删除倒数第n个节点，最后一个节点是倒数第一个
 * @author shkstart
 * @create 2022-08-14-16:54
 */
public class Jian22 {
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode low = head;
        ListNode fast = head;
        if (head == null || k == 0) {
            return null;
        }
        for (int i = 0; i < k; i++) {
            if (low == null) {
                return null;
            }
            low = low.next;
        }
        while (low != null) {
            fast = fast.next;
            low = low.next;
        }
        return fast;
    }
}
